import request from '@/utils/request'
import { randomId } from '@/utils'
import memCache from '@/utils/memCache'
// /scheme/getDetailById/{designId}
// 根据id获取详情-单空间
export function getDetailById(designId) {
  return request({
    method: 'GET',
    url: `/app/v1/scheme/getDetailById/${designId}`
  })
}
// /scheme/getRoomById/{designId}
// 根据id获取详情-全屋空间
export function getRoomById(designId) {
  return request({
    method: 'GET',
    url: `/app/v1/scheme/getRoomById/${designId}`
  })
}
// /scheme/getRoomPage
// 分页获取-全屋空间
export function getRoomPage(data) {
  return request({
    method: 'POST',
    url: `/app/v1/scheme/getRoomPage`,
    data,
    loading: false
  })
}
// /scheme/getRoomScreen
// 获取搜索条件-全屋空间
export function getRoomScreenFun() {
  return request({
    method: 'GET',
    url: `/app/v1/scheme/getRoomScreen`
  }).then(res => {
    const result = []
    // areaList 面积
    result.push({
      title: '面积',
      flag: 'areaList',
      unId: randomId(),
      children: (res.data.areaList || []).map((e, i) => {
        e.label = e.key
        // e.value = e.value
        e.index = i
        return e
      })
    })
    // 户型 hpList
    result.push({
      title: '户型',
      flag: 'hpList',
      unId: randomId(),
      children: (res.data.hpList || []).map((e, i) => {
        e.label = e.key
        // e.value = e.value
        e.index = i
        return e
      })
    })
    // 风格 styleList
    result.push({
      title: '风格',
      flag: 'styleList',
      unId: randomId(),
      children: (res.data.styleList || []).map((e, i) => {
        e.label = e.key
        // e.value = e.value
        e.index = i
        return e
      })
    })
    return {
      rawDdata: res.data,
      data: result
    }
  })
}
export const getRoomScreen = memCache('getRoomScreen', getRoomScreenFun)
// /scheme/getSingeAttribute
// 获取搜索条件-单空间
export function getSingeAttributeFun() {
  return request({
    method: 'GET',
    url: `/app/v1/scheme/getSingeAttribute`
  }).then(res => {
    // 处理数据结构，符合NavFilter组件
    const result = []
    // 品类 categoryList
    result.push({
      title: '品类',
      flag: 'categoryList',
      unId: randomId(),
      children: (res.data.categoryList || []).map((e, i) => {
        e.label = e.value
        e.value = e.key
        e.index = i
        return e
      })
    })
    result.push({
      title: '空间',
      flag: 'spaceList',
      unId: randomId(),
      multiple: true,
      children: (res.data.spaceList || []).map((e, i) => {
        return {
          label: e,
          value: e,
          index: i
        }
      })
    })
    result.push({
      title: '风格',
      flag: 'styleList',
      unId: randomId(),
      children: (res.data.styleList || []).map((e, i) => {
        e.label = e.styleName
        e.value = e.styleCode
        e.index = i
        // 系列
        e.title = `系列`
        e.unId = randomId()
        e.flag = `seriesList`
        e.children = (e.seriesList || []).map((c, i) => {
          c.label = c.seriesName
          c.value = c.seriesCode
          c.index = i
          return c
        })
        return e
      })
    })
    return {
      rawDdata: res.data,
      data: result
    }
  })
}
export const getSingeAttribute = memCache('getSingeAttribute', getSingeAttributeFun)
// /scheme/getSingePage
// 分页获取-单空间
export function getSingePage(data) {
  return request({
    method: 'POST',
    url: `/app/v1/scheme/getSingePage`,
    data,
    loading: false
  })
}
